const fs = require("fs");
const mammoth = require("mammoth");

// 读取docx文件并提取文字内容
exports.readDocxFile = async function (filePath) {
  try {
    const fileBuffer = fs.readFileSync(filePath);
    const result = await mammoth.extractRawText({ buffer: fileBuffer });
    return result.value;
  } catch (error) {
    console.error("读取文件时出错:", error);
  }
};

exports.isDocxFile = (filePath) => {
  return filePath.endsWith(".docx") || filePath.endsWith(".doc");
};
